const app = getApp()

Page({
  data: {
    jjsy:'',
    index:''
  },
  onShow(){
    wx.setNavigationBarTitle({
      title: '即将上映'
    })
  },
  onLoad: function (options) {
    let that = this;
    wx.getStorage({
      key: 'jjsy',
      success(res) {
        that.star(res)
        that.setData({
          jjsy: res.data
        })
      }
    })
  },
  navto(e) {
    let idx = e.currentTarget.id;
    this.setData({
      index: idx
    })
    wx.navigateTo({
      url: '/pages/dy_details/dy_details?index=' + this.data.index + '&icon=jjsy'
    })
  },
  star(res) {
    let yello, gray;
    for (let i = 0; i < res.length; i++) {
      if (res[i].rating.average >= 9) {
        res[i].rating.yello = 5;
        res[i].rating.gray = 0;
      } else if (res[i].rating.average >= 7) {
        res[i].rating.yello = 4;
        res[i].rating.gray = 1;
      } else if (res[i].rating.average >= 5) {
        res[i].rating.yello = 3;
        res[i].rating.gray = 2;
      } else if (res[i].rating.average >= 3) {
        res[i].rating.yello = 2;
        res[i].rating.gray = 3;
      } else if (res[i].rating.average >= 1) {
        res[i].rating.yello = 1;
        res[i].rating.gray = 4;
      } else {
        res[i].rating.yello = 0;
        res[i].rating.gray = 5;
      }
    }
    return res
  }
})
